// 模拟数据
const dockerImages = [
  {
    id: "sha256:1e0b",
    name: "nginx",
    tag: "latest",
    size: "133MB",
    created: "2 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:2f4a",
    name: "redis",
    tag: "alpine",
    size: "28.4MB",
    created: "3 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:3b7c",
    name: "postgres",
    tag: "13",
    size: "376MB",
    created: "1 month ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:4d8e",
    name: "<none>",
    tag: "<none>",
    size: "256MB",
    created: "5 days ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:5f9a",
    name: "<none>",
    tag: "<none>",
    size: "89MB",
    created: "1 week ago",
    architecture: "linux/arm64"
  },
  {
    id: "sha256:6a1b",
    name: "mysql",
    tag: "5.7",
    size: "379MB",
    created: "10 days ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:7c2d",
    name: "mongo",
    tag: "4.4",
    size: "396MB",
    created: "2 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:8e3f",
    name: "kafka",
    tag: "latest",
    size: "546MB",
    created: "1 week ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:9f4a",
    name: "rabbitmq",
    tag: "3-management",
    size: "128MB",
    created: "3 weeks ago",
    architecture: "linux/arm64"
  },
  {
    id: "sha256:ab5c",
    name: "elasticsearch",
    tag: "7.10",
    size: "725MB",
    created: "1 month ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:bd6e",
    name: "zookeeper",
    tag: "3.6",
    size: "142MB",
    created: "2 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:cf7a",
    name: "node",
    tag: "14-alpine",
    size: "110MB",
    created: "1 week ago",
    architecture: "linux/arm64"
  },
  {
    id: "sha256:df8b",
    name: "python",
    tag: "3.9-slim",
    size: "235MB",
    created: "10 days ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:ef9c",
    name: "jenkins",
    tag: "latest",
    size: "450MB",
    created: "3 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:ffad",
    name: "grafana",
    tag: "latest",
    size: "100MB",
    created: "2 weeks ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:0f1e",
    name: "prometheus",
    tag: "latest",
    size: "120MB",
    created: "1 month ago",
    architecture: "linux/arm64"
  },
  {
    id: "sha256:1a2b",
    name: "ubuntu",
    tag: "20.04",
    size: "72.8MB",
    created: "2 days ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:2b3c",
    name: "centos",
    tag: "7",
    size: "204MB",
    created: "1 week ago",
    architecture: "linux/amd64"
  },
  {
    id: "sha256:3c4d",
    name: "alpine",
    tag: "latest",
    size: "5.58MB",
    created: "3 days ago",
    architecture: "linux/arm64"
  },
  {
    id: "sha256:4d5e",
    name: "tomcat",
    tag: "9.0",
    size: "528MB",
    created: "2 weeks ago",
    architecture: "linux/amd64"
  }
];

const dockerVersion = {
  dockerVersion: "20.10.17",
  osVersion: "Linux 5.15.0-58-generic",
  composeVersion: "2.6.0"
};


const dockerDocs = [
  {
    "title": "Docker 安装指南",
    "url": "https://docs.docker.com/get-docker/",
    "description": "Docker 官方提供的安装指南，适用于各种操作系统。",
    "type": "官方"
  },
  {
    "title": "Docker Hub 使用手册",
    "url": "https://docs.docker.com/docker-hub/",
    "description": "如何使用 Docker Hub 来存储和分享容器镜像。",
    "type": "官方"
  },
  {
    "title": "Docker 容器管理教程",
    "url": "https://www.tutorialspoint.com/docker/",
    "description": "详细介绍了 Docker 容器的创建、运行和管理。",
    "type": "精选"
  },
  {
    "title": "Docker 网络配置指南",
    "url": "https://docs.docker.com/network/",
    "description": "如何配置 Docker 网络，实现容器间通信。",
    "type": "官方"
  },
  {
    "title": "Docker 存储卷管理",
    "url": "https://docs.docker.com/storage/",
    "description": "Docker 存储卷的使用方法和最佳实践。",
    "type": "工具"
  },
  {
    "title": "Docker 安全最佳实践",
    "url": "https://docs.docker.com/engine/security/",
    "description": "如何确保 Docker 环境的安全性。",
    "type": "官方"
  },
  {
    "title": "Docker Swarm 模式教程",
    "url": "https://docs.docker.com/engine/swarm/",
    "description": "使用 Docker Swarm 管理容器集群。",
    "type": "工具"
  },
  {
    "title": "Docker 与 Kubernetes 集成",
    "url": "https://docs.docker.com/kubernetes/",
    "description": "如何将 Docker 与 Kubernetes 结合使用。",
    "type": "官方"
  },
  {
    "title": "Docker 常见问题解答",
    "url": "https://docs.docker.com/faqs/",
    "description": "Docker 使用过程中常见问题的解答。",
    "type": "官方"
  },
  {
    "title": "Docker 监控与日志管理",
    "url": "https://docs.docker.com/config/daemon/logging/",
    "description": "如何监控 Docker 容器并管理日志。",
    "type": "官方"
  },
  {
    "title": "Docker Compose 指南",
    "url": "https://docs.docker.com/compose/",
    "description": "使用 Docker Compose 定义和运行多容器应用。",
    "type": "官方"
  },
  {
    "title": "Dockerfile 最佳实践",
    "url": "https://docs.docker.com/develop/dev-best-practices/",
    "description": "编写高效 Dockerfile 的最佳实践指南。",
    "type": "精选"
  },
  {
    "title": "Docker 多阶段构建",
    "url": "https://docs.docker.com/develop/dev-best-practices/",
    "description": "使用多阶段构建优化镜像大小。",
    "type": "工具"
  },
  {
    "title": "Docker Registry 部署",
    "url": "https://docs.docker.com/registry/",
    "description": "部署私有 Docker Registry 服务。",
    "type": "官方"
  },
  {
    "title": "Docker 性能调优",
    "url": "https://docs.docker.com/config/containers/resource_constraints/",
    "description": "Docker 容器性能优化和资源限制。",
    "type": "精选"
  }
];



// 在 dockerInfo.ts 中添加
const mockDockerStatus = {
  status: 'running',
  message: '服务正常运行中',
};


export default {
  'GET /docker-api/docker/images': (req: any, res: any) => {
    res.json({
      success: true,
      data: dockerImages,
      code: 200,
    });
  },
  'POST /docker-api/docker/images/pull': (req: any, res: any) => {
    res.json({
      success: true,
      data: true,
      errorCode: 0,
    });
  },
  'POST /docker-api/docker/images/upload': (req: any, res: any) => {
    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },
  'POST /docker-api/docker/images/delete': (req: any, res: any) => {
    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },
  'GET /docker-api/docker/version': (req: any, res: any) => {
    res.json({
      success: true,
      data: dockerVersion,
      code: 200,
    });
  },
  'GET /docker-api/docker/docs': (req: any, res: any) => {
    res.json({
      success: true,
      data: dockerDocs,
      code: 200,
    });
  },
  'POST /docker-api/docker/images/import': (req: any, res: any) => {
    const { path } = req.body;
    // 验证路径前缀
    const prefix = path.charAt(0).toUpperCase();
    if (!['W', 'F', 'D'].includes(prefix)) {
      res.json({
        success: false,
        message: '无效的路径前缀',
        code: 400,
      });
      return;
    }

    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },

  'POST /docker-api/docker/images/tag': (req: any, res: any) => {
    const { imageId, newTag } = req.body;
    // 模拟标签格式验证
    if (!newTag.includes(':')) {
      res.json({
        success: false,
        message: '标签格式错误',
        code: 400,
      });
      return;
    }

    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },



  'GET /docker-api/docker/service/status': (req: any, res: any) => {
    res.json({
      success: true,
      data: mockDockerStatus,
      code: 200,
    });
  },

  'POST /docker-api/docker/service/start': (req: any, res: any) => {
    mockDockerStatus.status = 'running';
    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },

  'POST /docker-api/docker/service/stop': (req: any, res: any) => {
    mockDockerStatus.status = 'stopped';
    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },

  'POST /docker-api/docker/service/restart': (req: any, res: any) => {
    mockDockerStatus.status = 'running';
    res.json({
      success: true,
      data: true,
      code: 200,
    });
  },
};
